﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace CorporationWars
{
    [Serializable]
    public class UICheckBox : UIZone
    {
        public string Text { get; set; }
        public int Size { get; set; }
        public bool Value { get; set; }
        protected string _FontAsset { get; set; }
        public string FontAsset 
        {
            get
            {
                if (_FontAsset == null)
                    _FontAsset = "Fonts/font";

                return _FontAsset;
            }
            set
            {
                _FontAsset = value;
            }
        }

        public UICheckBox(Game1 game) : base(game) { }

        public override void Update(GameTime gameTime)
        {
            if (Width == 0)
            {
                Width = Size + (int)Game.Content.Load<SpriteFont>(FontAsset).MeasureString(Text).X + 8;
                Height = Size;
            }
            
            base.Update(gameTime);
            
        }

        public override void Draw(GameTime gameTime)
        {
            if (!IsVisible)
                return;
            
            if (Value)
                spriteBatch.Draw(Game.Content.Load<Texture2D>("Textures/HUD/CheckBoxs/checkBoxTrue"), new Rectangle((int)Position.X, (int)Position.Y, Size, Size), Color.White);
            else
                spriteBatch.Draw(Game.Content.Load<Texture2D>("Textures/HUD/CheckBoxs/checkBoxFalse"), new Rectangle((int)Position.X, (int)Position.Y, Size, Size), Color.White);

            if (Text != string.Empty)
            {
                // background..
                Vector2 textPos = Position + new Vector2(Size + 8, Size / 6);
                spriteBatch.Draw(Game.Content.Load<Texture2D>("Textures/HalfShadeToNothing"), new Rectangle((int)textPos.X - 8, (int)textPos.Y - 5, Width, Size), Color.White);
                Game.RenderText(Text, textPos, Color, -1, FontAsset);
            }

            if (IsMouseOver)
                DrawToolTip(gameTime);
        }
    }
}
